import React from 'react';
import { inject, observer } from 'mobx-react';
import { formatter } from '../util';
import {
  WeaTop,
  WeaRightMenu,
  WeaErrorPage,
  WeaTools,
  WeaNewScroll,
  WeaLocaleProvider,
} from 'ecCom';
import CountContent from './count/CountContent';
import { toJS } from 'mobx';

const getLabel = WeaLocaleProvider.getLabel;
@inject('docCountStore')

@observer
class Count extends React.Component {
  constructor(props){
    super(props);
    this.state={
      collectParams:{
        favname: getLabel(132045, '阅读量统计'),
        favouritetype: 2,
        objid: 0,
        importantlevel: 1,
        link: 'wui/index.html#/main/document/count',
      },
      dropMenuProps:{
        collectParams: {
          favname: getLabel(132045, '阅读量统计'),
          favouritetype: 2,
          objid: 0,
          importantlevel: 1,
          link: 'wui/index.html#/main/document/count',
        },
      }
    }
  }
  componentDidMount() {
    const { docCountStore } = this.props;
    const { getCondition, getPeopleNum, getDocNum
      , getReadPeopleNum, getReportData } = docCountStore;
    getCondition();
    getPeopleNum();
    getDocNum();
    getReadPeopleNum();
    getReportData();
  }
  componentWillReceiveProps() {
  }
  componentWillUnmount() {
  }
  onRightMenuClick() {
    const Arr = [];
    return Arr;
  }
  getRightMenu() {
    const Arr = [
    ];
    return Arr;
  }
  getButtons() {
    const Arr = [];
    return Arr;
  }

  render() {
    const { docCountStore } = this.props;
    const { reportData, subdepartment, department, title
      , loading, loadingChart, loadingRPN, loadingPN, loadingDN } = docCountStore;
    const loadingNow = loading || loadingChart || loadingRPN || loadingPN || loadingDN;
    // 图表_初始化数据
    let ydata = [];
    let xdata = [];
    if (toJS(reportData).datas) {
      toJS(reportData).datas.forEach((item) => {
        ydata.push(item.docNum);
        xdata.push(`${formatter(item.name)}(${getLabel(30042, '人员')}ID : ${item.operateuserid})`);
      });
    }
    return (
      <div className="wea-doc-count">
        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@xh4vh9`}
          collectParams={this.state.collectParams}
          datas={this.getRightMenu()}
          onClick={this.onRightMenuClick}
        >
          <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@ni8fl9`}
            title={title}
            loading={loadingNow}
            icon={<i className="icon-coms-doc" />}
            iconBgcolor="#df583a"
            buttons={this.getButtons()}
            buttonSpace={10}
            showDropIcon
            dropMenuDatas={this.getRightMenu()}
            dropMenuProps={this.state.dropMenuProps}
            onDropMenuClick={this.onRightMenuClick}
          >
            <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@5afcnx`} height={'100%'}>
              <CountContent ecId={`${this && this.props && this.props.ecId || ''}_CountContent@vkbdcw`} ydata={ydata} xdata={xdata} subdepartment={subdepartment} department={department} />
            </WeaNewScroll>
          </WeaTop>
        </WeaRightMenu>
      </div>
    );
  }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@535osj`} msg={props.error ? props.error : getLabel(385218, '对不起，该页面异常，请联系管理员！')} />,
  { error: '' },
)(Count);

